*************************
*************************
***Instrumentos Valora***
*************************
*************************

clear
set more off

use "$base_out/Observacion_indices.dta"

***Traigo base de herramientas***

merge 1:1 cct using "$base_out/Herramientas_indices.dta", gen(_herramientas)

***Dejo solo la muestra con observacion en los indicadores de interes***

keep if Indice_total!=. | Indice_uso!=. | IndiceH_total!=. | IndiceH_uso!=. 

merge 1:1 cct using "$basein/Datos adicionales/Tratamientos_completos.dta"

keep if _merge==3

rename cct school_id

merge m:1 school_id using "$basein/Datos adicionales/estratos.dta", gen(_estratos)

drop if estrato==13 | estrato==15

merge 1:1 school_id using "$basein/Datos adicionales/secundarias.dta", gen(_secundaria)

keep if _secundaria==3

*****************************
***Elimino las secundarias***
*****************************

drop if secondary==1

drop if treatgroup2==""

gen PEC_Plus=0
replace PEC_Plus=1 if treatgroup2=="PEC Plus"

gen PEC=0
replace PEC=1 if treatgroup2=="PEC"

label var PEC_Plus " "
label var PEC" "

******************
***KEEP´ONLY PEC VS PEC PLUS******
******************

drop if state==10
drop if treatgroup2=="Control"
drop if treatgroup2==""
**********************************
*****Estandarizo los índices******
**********************************

foreach x in Indice_total Indice_uso IndiceH_total IndiceH_uso {

egen std_`x'=std(`x')

}

**********************
*****Regresiones******
**********************

********************
**PEC PLUS vs. PEC**

eststo clear
foreach x in std_Indice_total std_Indice_uso std_IndiceH_total std_IndiceH_uso {

eststo: reghdfe `x'  PEC_Plus if (treatgroup2!="Control" & state!=10) , a(estrato)  vce(cluster school_id)
estadd ysumm
sum `x' if e(sample)==1 & treatgroup=="PEC" & state!=10
estadd scalar ymean2=r(mean)

}


esttab using "$tables/Valora_1.tex" ,  fragment se ar2  label b(a2) se(a2) nocon nonumber nomtitles nolines nogaps /// 
replace collabels(none)  ///
keep(PEC_Plus) stats(N ymean2, fmt("%9.2gc" "%9.2fc") labels("No. of obs." "Control mean")) star(* 0.10 ** 0.05 *** 0.01)

